home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / unix / src / devices.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-19  |  754 b   |  34 lines

  1. #include "amiga.h"
  2. #include "devices.h"
  3.  
  4. struct IORequest *_device_open(char *name, ULONG unit, ULONG flags,
  5.                    APTR data, ULONG data_len, int req_size)
  6. {
  7.     struct MsgPort *port;
  8.     struct IORequest *ioreq;
  9.  
  10.     if ((port = CreateMsgPort()) && (ioreq = CreateIORequest(port, req_size)))
  11.     {
  12.     if (data)
  13.     {
  14.         struct IOStdReq *io2 = (struct IOStdReq *)ioreq;
  15.         io2->io_Data = data;
  16.         io2->io_Length = data_len;
  17.     }
  18.     if (OpenDevice(name, unit, ioreq, flags) == 0) return ioreq;
  19.     }
  20.     if (ioreq) DeleteIORequest(ioreq);
  21.     if (port) DeletePort(port);
  22.     return 0;
  23. }
  24.  
  25. void _device_close(struct IORequest *ioreq)
  26. {
  27.     if (ioreq)
  28.     {
  29.     CloseDevice(ioreq);
  30.     DeletePort(ioreq->io_Message.mn_ReplyPort);
  31.     DeleteIORequest(ioreq);
  32.     }
  33. }
  34.